<%@page import="java.util.HashMap"%>
<%@page import="model.ViewProduct"%>
<%@page import="helperclasses.Product"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ include file="MainBricks/includeStuff.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Atrium Home Page</title>
<link href="style/style.css" rel="stylesheet" type="text/css" media="screen" />
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css"
	type="text/css" media="all" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script type="text/javascript" src="js/addfieldscocktail.js"></script>
</head>
<body>
	<script type="text/javascript">
		var contor = 0;
		function addAutocomplete() {			
			contor += 1;
			$("#autocompleteinput" + contor).autocomplete({
				source :
				${productsNames}
		});
		}
		function test() {
			var e = document.getElementById("tipNir"); // select element
			var strUser = e.options[e.selectedIndex].value;
			if (strUser == 3) {
				addLinks();
			} else {
				removeAll();
			}
		}
		
		function verifyCheckbox() {
			if(document.getElementById('checkbox1').checked == true){
					document.getElementById('alterlog').value='isChecked';
					addTextArea();
				} else {
					document.getElementById('alterlog').value='isNotChecked';
					removeElementTextArea();
				}
		}
		
	</script>
	<div id="wrapper">
		<%@ include file="MainBricks/header.jsp"%>
		<!-- end #header -->
		<%@ include file="MainBricks/topmenu.jsp"%>
		<!-- end #menu -->
		<div id="page">
			<div id="page-bgtop">
				<div id="page-bgbtm">
					<div id="content">
						<%@ include file="MainBricks/includeinContent.jsp"%>
						<c:if test="${not empty editResult}">
							<h3>${editResult}</h3>
						</c:if>
						<c:choose>
							<c:when test="${product.productId == 0 }">
								<h2>
									<c:out value="Invalid Request!!"></c:out>
								</h2>
							</c:when>
							<c:otherwise>
								<fieldset>
									<legend>Product: ${product.productName}</legend>
									<form name="input" action="product.do" method="post" class="stockform">
										<table id="areatextarea">
											<c:if test="${mode == 'view' }">
												<tr>
													<td>Product Id:</td>
													<td><input type="text" name="productId" value="${product.productId}" readonly="readonly" /></td>
												</tr>
											</c:if>
											<tr>
												<td>Nume Produs:</td>
												<td><input type="text" name="productName" value="${product.productName}" required="required" /></td>
											</tr>
											<tr>
												<td>Valoare (L, kg, g, buc.):</td>
												<td><input type="text" name="valoare" value="${product.valoare}" required="required" /></td>
											</tr>
											<tr>
												<td>Pret de Vanzare:</td>
												<td><input type="text" name="pretIesire" value="${product.pretIesire}" required="required" /></td>
											</tr>
											<tr>
												<td>Cantitate (buc. in stoc):</td>
												<td><input type="text" name="cantitate" value="${product.cantitate}" required="required" />
													<input type="hidden" name="cantitatehidden" value="${product.cantitate}" /></td>
											</tr>

											<c:if test="${product.tipNir == 1 or product.tipNir == 3 }">

												<input type="hidden" name="valoareInStoc" value="${product.valoareInStoc}" required="required" />
											</c:if>
											<c:if test="${product.tipNir == 2 or product.tipNir == 4 }">
												<tr>
													<td>Valoare in stoc:</td>
													<td><input type="text" name="valoareInStoc" value="${product.valoareInStoc}"
														required="required" /></td>
												</tr>
											</c:if>
											<tr>
												<td>Unitate de Masura</td>
												<td><select name=um>
														<c:forEach items="${unimasura }" var="unitateMasura">
															<c:choose>
																<c:when test="${unitateMasura eq product.unitateMasura }">
																	<option selected="selected">${unitateMasura}</option>
																</c:when>
																<c:otherwise>
																	<option>${unitateMasura}</option>
																</c:otherwise>
															</c:choose>
														</c:forEach>
												</select></td>
											</tr>
											<tr>
												<td>Tip NIR</td>
												<td><select id=tipNir name="tipNir" onchange='test()'>
														<option selected="selected" label="Tip ${product.tipNir}">${product.tipNir}</option>
														<option label="Tip 1">1</option>
														<option label="Tip 2">2</option>
														<option label="Tip 3">3</option>
														<option label="Tip 4">4</option>
												</select></td>
											</tr>
											<c:if test="${mode == 'view' }">
												<tr>
													<td></td>
													<td><input type="checkbox" id="checkbox1" name="checkbox" onclick="verifyCheckbox()" />Save
														changes to log<br /> <input type="hidden" id="alterlog" name="alterlog"></td>
												</tr>
											</c:if>
										</table>
										<c:if test="${product.tipNir == 3}">
											<table>
												<tr>
													<td colspan='4'><center>
															<a onclick='addTextBox(); addAutocomplete()' href='#'>Adauga Ingredient </a>
															&nbsp;&nbsp;|&nbsp;&nbsp; <a onclick='removeElement(); removeAutoComplete()' href='#'>Sterge
																Ingredient</a>
														</center></td>
												</tr>
											</table>
										</c:if>
										<table id="area">
											<c:if test="${product.tipNir == 3}">
												<c:forEach items="${product.ingredients}" var="ingr" varStatus="ingrcount">
													<script type="text/javascript">
													var prodName = '"<c:out value="${ingr.value.productName}"/>"';
													var valoare = '"<c:out value="${ingr.value.valoareInStoc}"/>"';						
													addTextBox1(prodName, valoare);
													addAutocomplete();
													</script>
												</c:forEach>
											</c:if>
										</table>
										<br>
										<table>
											<tr>
												<td></td>
												<c:choose>
													<c:when test="${mode == 'view' }">
														<td style="float: right; margin-right: 50px" class="submit"><input type="submit"
															name="edit" value=Edit /><input type="submit" name="delete" value="Delete" /></td>
													</c:when>
													<c:when test="${mode == 'add' }">
														<td style="float: right; margin-right: 50px" class="submit"><input type="submit"
															name="save" value=Save /></td>
													</c:when>
													<c:otherwise></c:otherwise>
												</c:choose>
											</tr>
										</table>
									</form>
								</fieldset>
							</c:otherwise>
						</c:choose>

					</div>
					<!-- end #content -->
					<%@ include file="MainBricks/leftmenu.jsp"%>
					<!-- end #sidebar -->
					<div style="clear: both;">&nbsp;</div>
				</div>
			</div>
		</div>
		<!-- end #page -->
	</div>
	<%@ include file="MainBricks/footer.jsp"%>
	<!-- end #footer -->
</body>
</html>